<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>H+ 后台主题UI框架 - Bootstrap Table</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="/admin/favicon.ico"> <link href="/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/admin/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="/admin/css/animate.css" rel="stylesheet">
    <link href="/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <script src="/admin/js/jquery.min.js?v=2.1.4"></script>
    <style>
        a{
            color:#777;
        }
    </style>

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <!-- Example Events -->
                    <div class="example-wrap">
                        <div class="example">
                            <div class="btn-group hidden-xs" id="tabtar" role="group">
                                <button type="button" class="btn btn-primary" onclick="add()">
                                    <i class="glyphicon glyphicon-plus" aria-hidden="true"></i> 添加
                                </button>
                                <button id='dels' type="button" class="btn btn-warning">
                                    <i class="glyphicon glyphicon-trash" aria-hidden="true"></i> 批量删除
                                </button>
                            </div>
                            <table data-toggle="table" id="table"> 
                                <thead>
                                    <tr>
                                        <th data-field="state" data-checkbox="true"></th>
                                        <th data-field="id" data-sortable='true'>ID</th>
                                        <th data-field="name">商品名</th>
                                        <th data-field="type">所属分类</th>
                                        <th data-field="img">图片</th>
                                        <th data-field="price">价格</th>
                                        <th data-field="details">详情</th>
                                        <th data-fiele="size">规格</th>
                                        <th data-fiele="keywords">关键字</th>
                                        <th data-field="created_at">加入时间</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($arr as $list)
                                    <tr>
                                        <td></td>
                                        <td>{{$list->id}}</td>
                                        <td>{{$list->name}}</td>
                                        <td>{{$list->type}}</td>
                                        <td><img src="/upload/x_{{$list->img}}" alt="" width="100"></td>
                                        <td>{{$list->price}}</td>
                                        <td>
                                            <a href="javascript:;" onclick="dtShow({{$list->id}})">查看详情</a>
                                        </td>
                                        <td>
                                            <a href="javascript:;" onclick="gsList({{$list->id}})">查看规格</a>
                                        </td>
                                        <td>{{$list->keywords}}</td>
                                        <td>{{$list->created_at}}</td>
                                        <td>
                                            <a href="javascript:;" class='glyphicon glyphicon-pencil edit' onclick="edit(this,{{$list->id}})" title='修改'></a>
                                            <a href="javascript:;" class='glyphicon glyphicon-trash del' onclick="del({{$list->id}})" title='删除'></a>
                                        </td>
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!-- End Example Events -->
                </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="/admin/js/layer.js"></script>

    <!-- 自定义js -->
    <script src="/admin/js/content.js?v=1.0.0"></script>


    <!-- Bootstrap table -->
    <script src="/admin/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="/admin/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    <script src="/admin/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

    <!-- jQuery Validation plugin javascript-->
    <!-- <script src='/admin/js/plugins/validate/jquery.validate.min.js'></script>
    <script src='/admin/js/plugins/validate/messages_zh.min.js'></script>

    <script src='/admin/js/demo/form-validate-demo.js'></script> -->
    <script src="/laydate/laydate.js"></script>

    <!-- Peity -->
    <!-- <script src="/admin/js/demo/bootstrap-table-demo.js"></script> -->
    <script src="/admin/js/plugins/iCheck/icheck.min.js"></script>
    <script src="/admin/js/plugins/peity/jquery.peity.min.js"></script>
    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
    <!--统计代码，可删除-->
    <script>
        // 删除函数
        function del(ids){
            if(typeof ids!='object' & ids!='none'){
                arr=new Array();
                arr[0]=ids.toString(); // 将数字转为数组
                ids=arr;
            }
            if (ids!=='none') {
                layer.confirm('你确定要删除吗？', {
                    btn: ['删除','取消']
                }, function(){
                    // ajax传输数据并响应
                    $.post("/admin/goods/goods_del",{"_method":"DELETE","ids":ids},function(data){
                        // console.log(data);
                        if (data == 1) {
                            layer.msg('删除成功', {icon: 1});
                            //删除bt表格中的选中行
                            $('#table').bootstrapTable('remove', {
                                field: 'id',
                                values: ids
                            });
                        }else{
                            layer.msg('删除失败',{icon: 2});
                        }
                    }).done(function(){
                        $('#table').bootstrapTable('uncheckAll');// 取消选中所有行
                    }).fail(function(data){
                        // console.log(data);
                    })
                }, function(){
                    layer.msg('已取消',{icon: 2});
                    $('#table').bootstrapTable('uncheckAll');
                });
            }else{
                layer.msg('未选择数据');
            }
        }
        //删除
        $('#dels').click(function(){
            var idarr=$.map($('#table').bootstrapTable('getSelections'), function (row){
                return row.id;
            }); //获取选中行(数组)
            var ids = $('#table').bootstrapTable('getSelections')[0]?idarr:'none';
            // 调用删除函数
            del(ids);
        });
        // 修改
        function edit(thiss,id){
            var index=$(thiss).parent().parent().index();  //当前行下标
            $('#table').bootstrapTable('check',index);  //选中当前行
            var olddata=$('#table').bootstrapTable('getSelections')[0];//当前行信息
            // 打开修改页
            layer.open({
                type: 2,
                title: '修改信息',
                skin: 'layui-layer-demo', //样式类名
                // closeBtn: false, //不显示关闭按钮
                // scrollbar: false, //屏蔽滚动
                area: ['1000px', '600px'],
                anim: 0,
                shadeClose: true, //开启遮罩关闭
                content:"/admin/goods/goods_edit?id="+id,
                // success:
                cancel:function(){  
                    layer.msg('已取消修改');
                },
                end:function(){
                    $('#table').bootstrapTable('uncheckAll');// 取消选中所有行
                }
            });
        }

        // 添加
        function add(){
            var index=layer.open({
                type: 2,
                title: '添加商品',
                maxmin: true, //最大小化
                shadeClose: true, //点击遮罩关闭层
                area : ['1000px' , '600px'],
                content: '/admin/goods/goods_add',
                cancel:function(){
                    layer.msg('取消添加',{'icon':2});
                }
            });
        }
    </script>
    <script>
    // 商品规格页面
        function gsList(gid){
            var index=layer.open({
                type: 2,
                title: '商品规格列表',
                maxmin: true, //最大小化
                shadeClose: true, //点击遮罩关闭层
                area : ['100%' , '100%'],
                content: '/admin/goods/goodssize_list?gid='+gid,
                cancel:function(){
                    layer.msg('取消查看');
                }
            });
        }
    // 详情展示页面
        function dtShow(id){
            var index=layer.open({
                type:2,
                title: '商品详情',
                shadeClose: true, //点击遮罩关闭层
                area:['1000px','100%'],
                content: '/admin/goods/goods_details?id='+id,
            })
        }
    </script>
    <script>
        // bt表格样式
        $('#table').bootstrapTable({
            search:true,
            showRefresh:true,
            showColumns:true,
            showToggle:true,
            pagination:true,
            cache:false,
            pageSize:'5',
            iconSize:'outline',
            toolbar: '#tabtar',
        });
        // 刷新功能
        // $('#table').bootstrapTable('refresh',{url:'/'});
    </script>

</body>

</html>
